<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="org.json.simple.*, java.util.TreeMap, com.classes.Casemast, com.classes.CaseOutlet, com.classes.Outlet" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%
	String selection = "";
	String visa_1 = "";
	String visa_2 = "";
	String visa_3 = "";
	String amex_1 = "";
	String amex_2 = "";
	
	if(request.getAttribute("c_outlet") != null) {
		if(((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getStatementOpt().length() > 0) {
			JSONObject obj = (JSONObject) JSONValue.parse(((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getStatementOpt());

			visa_1 = (obj.get("visa_1") == null) ? "" : obj.get("visa_1").toString();
			visa_2 = (obj.get("visa_2") == null) ? "" : obj.get("visa_2").toString();
			visa_3 = (obj.get("visa_3") == null) ? "" : obj.get("visa_3").toString();
			
			amex_1 = obj.get("amex_1") == null ? "" : obj.get("amex_1").toString();
			amex_2 = obj.get("amex_2") == null ? "" : obj.get("amex_2").toString();
		}
	}
	
	boolean outlet_newable = true;
	boolean outlet_deletable = true;
	
	TreeMap<String, String> viewAccess = (TreeMap<String, String>) request.getAttribute("view_access");
	if(viewAccess.get("view_as").equals("maker") == false && viewAccess.get("view_as").equals("admin") == false){
		outlet_newable = false;
		outlet_deletable = false;
	}
	
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="include/html-meta.jsp" />
<title>MAYBANK</title>
<script src="<%= request.getContextPath() %>/js/outlet.js"></script>
</head>

<body>

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->

<div class="row-fluid page">
	<div class="span12">

		<jsp:include page="include/tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("application") %>' />
		</jsp:include>
		
		<jsp:include page="include/app-tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("outlet_info") %>' />
		</jsp:include>
		
		<div class="row-fluid outlet-main-content">
			<div class="span2">
				<ul class="outletlist">
				<%
					String html = "";
					String css_class = "";
					
					for(CaseOutlet a : ((Casemast)request.getAttribute("m_case")).getOutlets()){
						Outlet o = a.getOutlet();
						
						css_class = "";
						
						if(request.getAttribute("c_outlet") != null) {
							if(o.getId() == ((CaseOutlet) request.getAttribute("c_outlet")).getOutlet().getId()){
								css_class = " class=\"active\"";
							}
						}
						
						html = "<li" + css_class + "><a href=\"javascript:tab.load('/NewApp.do?dispatch=statement_option&o_id=" + EncryptionHelper.encryptEncodeURL(o.getId()+"") + "', '')\">" + o.getName() + "</a></li>";
						
						out.println(html);
					}
					
					css_class = " class=\"addnew\"";
					if(request.getAttribute("c_outlet") == null) {
						css_class = " class=\"addnew active\"";
					}
					
					if(outlet_newable){
						html = "<li" + css_class + "><a href=\"javascript:tab.load('/NewApp.do?dispatch=outlet_create', '&?o_id=[0-9]+&?')\">New Outlet</a></li>";
						out.println(html);
					}
				%>
				</ul>
				
				<div>
					
					<%
						if(outlet_newable){
							html = "<a class=\"btn\" href=\"javascript:tab.load('/NewApp.do?dispatch=outlet_create', '&?o_id=[0-9]+&?')\">Add</a>";
							out.println(html);
						}
					
						if(outlet_deletable && request.getAttribute("c_outlet") != null){
							html = "<button type=\"button\" class=\"btn\" onclick=\"outlet.delete_submit('" + EncryptionHelper.encrypt(request.getAttribute("case_id")+"") + "', '" + EncryptionHelper.encrypt(request.getAttribute("merchant_id")+"") + "', '" + EncryptionHelper.encrypt(((CaseOutlet) request.getAttribute("c_outlet")).getOutlet().getId()+"") + "')\">Delete</button>";
							out.println(html);
						}
					%>
					
				</div>
			</div>
			
			<div class="span10" style="border-left:1px solid #eee">
				<jsp:include page="include/outlet-tab.jsp">
					
					<jsp:param name="active" value='<%=EncryptionHelper.encrypt("statement_option") %>' />
				</jsp:include>
	
	
				<div class="form-horizontal" style="padding:0px 30px">
					<table style="width:100%">
						<tr>
							<td class="title" colspan="2">
								Merchant Statement Option 
								<a class="link" data-type="visa_master" href="javascript:;" onclick="outlet.statement_option_reset(this)">Deselect Visa/Master/Amex Statement</a>
							</td>
						</tr>
						<tr>
							<td style="width:40%"><label class="radio inline-block"><input type="radio" name="visa_1" value="By Merchant Portal Service" <%= visa_1.equals("By Merchant Portal Service") ? "checked" : "" %> />By Merchant Portal Service</label></td>
							<td style="width:60%">Email Address <input type="text" id="visa_2" style="margin-left:20px" value="<%= visa_2 %>" /></td>
						</tr>
						<tr>
							<td></td>
							<td>Email Address <input type="text" id="visa_3" style="margin-left:20px" value="<%= visa_3 %>" /></td>
						</tr>
						<tr>
							<td><label class="radio inline-block"><input type="radio" name="visa_1" value="By M2E Service" <%= visa_1.equals("By M2E Service") ? "checked" : "" %> />By M2E Service</label></td>
							<td></td>
						</tr>
						<tr>
							<td><label class="radio inline-block"><input type="radio" name="visa_1" value="By e-Commerce Report" <%= visa_1.equals("By e-Commerce Report") ? "checked" : "" %> />By e-Commerce Report</label></td>
							<td></td>
						</tr>					
						<tr>
							<td class="title" colspan="2" style="padding-top:50px">
								Amex Statement Option 
								<a class="link" data-type="amex" href="javascript:;" onclick="outlet.statement_option_reset(this)">Deselect Amex Statement Option Only</a>
							</td>
						</tr>
						<tr>
							<td><label class="radio inline-block"><input type="radio" name="amex_1" value="By Online Merchant Services" <%= amex_1.equals("By Online Merchant Services") ? "checked" : "" %> />By Online Merchant Services</label></td>
							<td>Email Address <input type="text" id="amex_2" style="margin-left:20px" value="<%= amex_2 %>" /></td>
						</tr>
					</table>
				</div>
			</div>
			
		</div>
		
		<div class="row-fluid">
			<div class="span12 btn-control">
				<input id="click_redirect" name="click_redirect" type="hidden" value="" />
				<input id="click_filter" name="click_filter" type="hidden" value="" />
				<button type="submit" class="btn" id="submit" onclick="outlet.create_statement_opt('<%= request.getParameter("c_id") %>', '<%= request.getParameter("o_id") %>')">Save</button>
			</div>
		</div>
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->

</body>
</html>